home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_gimp.idb / usr / freeware / share / gimp / scripts / fade-outline.scm.z / fade-outline.scm
Encoding:
GIMP Script-Fu Script  |  1999-07-21  |  5.2 KB  |  153 lines

  1. ; fade-outline.scm
  2. ; version 1.1
  3. ;
  4. ; This GIMP script_fu operates on a single Layer
  5. ; It makes it's outline boarder transparent by
  6. ; adding a layer mask that is black (transparent) at the outline
  7. ; and blends into white (opaque) at the inner regions of the
  8. ; shape. The user can specify the thickness of the fading border
  9. ; that is used to blend from transparent to opaque.
  10. ;
  11. ; The outline is taken from the current selection
  12. ; or from the layers alpha channel if no selection is active.
  13. ;
  14. ; Optional you may keep the generated layermask or apply
  15. ; it to the layer 
  16.  
  17. ;
  18. ; The GIMP -- an image manipulation program
  19. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  20. ; This program is free software; you can redistribute it and/or modify
  21. ; it under the terms of the GNU General Public License as published by
  22. ; the Free Software Foundation; either version 2 of the License, or
  23. ; (at your option) any later version.
  24. ; This program is distributed in the hope that it will be useful,
  25. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  27. ; GNU General Public License for more details.
  28. ; You should have received a copy of the GNU General Public License
  29. ; along with this program; if not, write to the Free Software
  30. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  31.  
  32.  
  33. ; Define the main function:
  34.  
  35. (define (script-fu-fade-outline   inImage
  36.                                   inLayer 
  37.                                   inBorderSize
  38.                                   inApplyMask
  39.                                   inClearUnselected
  40.         )
  41.  
  42.         (let* ((l-idx 0)
  43.                (l-step (/ 25500 (+ inBorderSize 1)))
  44.                (l-gray l-step)
  45.                (l-old-bg-color (car (gimp-palette-get-background)))
  46.                (l-has-selection TRUE)            
  47.  
  48.               )
  49.  
  50.         ; do nothing if the layer is a layer mask
  51.         (if (= (car (gimp-drawable-layer-mask inLayer)) 0)
  52.             (begin
  53.  
  54.               (gimp-undo-push-group-start inImage)
  55.               
  56.               ; if the layer has no alpha add alpha channel
  57.               (if (= (car (gimp-drawable-has-alpha inLayer)) FALSE)
  58.                   (begin
  59.                      (gimp-layer-add-alpha inLayer)
  60.                   )
  61.                )
  62.  
  63.               ; if the layer is the floating selection convert to normal layer
  64.               ; because floating selection cant have a layer mask
  65.               (if (> (car (gimp-layer-is-floating-sel inLayer)) 0)
  66.                   (begin
  67.                      (gimp-floating-sel-to-layer inLayer)
  68.                   )
  69.                )
  70.  
  71.               ; if there is no selection we use the layers alpha channel
  72.               (if (= (car (gimp-selection-is-empty inImage)) TRUE)
  73.                   (begin
  74.                      (set! l-has-selection FALSE)
  75.                      (gimp-selection-layer-alpha inImage inLayer)
  76.                   )
  77.                )
  78.  
  79.                ; apply the existing mask before creating a new one
  80.               (gimp-image-remove-layer-mask inImage inLayer 0)
  81.  
  82.               (if (= inClearUnselected  TRUE)
  83.                   (begin
  84.                     (set! l-mask (car (gimp-layer-create-mask inLayer BLACK-MASK)))
  85.                    )
  86.                   (begin
  87.                     (set! l-mask (car (gimp-layer-create-mask inLayer WHITE-MASK)))
  88.                   )
  89.                )
  90.  
  91.               (gimp-image-add-layer-mask inImage inLayer l-mask)
  92.                                            
  93.               (while (<= l-idx inBorderSize)
  94.                  (if (= l-idx inBorderSize)
  95.                      (begin
  96.                         (set! l-gray 25500)
  97.                       )
  98.                   )
  99.                   (gimp-palette-set-background (list (/ l-gray 100) (/ l-gray 100) (/ l-gray 100)))
  100.                   (gimp-edit-fill inImage l-mask)
  101.                   (set! l-idx (+ l-idx 1))
  102.                   (set! l-gray (+ l-gray l-step))
  103.                   (gimp-selection-shrink inImage 1)
  104.                   ; check if selection has shrinked to none
  105.                   (if (= (car (gimp-selection-is-empty inImage)) TRUE)
  106.                       (begin
  107.                          (set! l-idx (+ inBorderSize 100))     ; break the while loop
  108.                       )
  109.                    )
  110.  
  111.               )
  112.  
  113.               (if (=  inApplyMask TRUE)
  114.                   (begin
  115.                     (gimp-image-remove-layer-mask inImage inLayer 0)
  116.                   )
  117.                )
  118.  
  119.               (if (= l-has-selection FALSE)
  120.                   (gimp-selection-none inImage)
  121.               )
  122.  
  123.              (gimp-palette-set-background l-old-bg-color)
  124.              (gimp-undo-push-group-end inImage)
  125.              (gimp-displays-flush)
  126.              )
  127.         ))  
  128. )
  129.  
  130.  
  131.  
  132.  
  133. ; Register the function with the GIMP:
  134. ; ------------------------------------
  135.  
  136. (script-fu-register
  137.     "script-fu-fade-outline"
  138.     "<Image>/Script-Fu/Selection/Fade Outline"
  139.     "Blend the Layers outline border to transparent"
  140.     "Wolfgang Hofer <wolfgang.hofer@siemens.at>"
  141.     "Wolfgang Hofer"
  142.     "19 May 1998"
  143.     "RGB RGBA GRAY GRAYA"
  144.     SF-IMAGE "The Image" 0
  145.     SF-DRAWABLE "The Layer" 0
  146.     SF-VALUE "Border Size:" "10"
  147.     SF-TOGGLE "Apply generated Layermask?" FALSE
  148.     SF-TOGGLE "Clear unselected Maskarea?" TRUE
  149. )
  150.